

import com.it.DoubleLinkedList;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

class DoubleLinkedListTest {

    private DoubleLinkedList<String> list;

    @BeforeEach
    void setUp() {
        list = new DoubleLinkedList<>();
    }

    @Test
    void testAddToEmptyList() {
        // 测试链表为空时添加元素
        boolean result = list.add("A");

        assertTrue(result);
        assertEquals(1, list.size);
        assertNotNull(list.head.getNext());
        assertEquals("A", list.head.getNext().getData());
        assertEquals(list.head.getNext(), list.head.getPre());
    }

    @Test
    void testAddToNonEmptyList() {
        // 测试链表不为空时添加元素
        list.add("A");
        boolean result = list.add("B");

        assertTrue(result);
        assertEquals(2, list.size);
        assertNotNull(list.head.getPre());
        assertEquals("B", list.head.getPre().getData());
        assertEquals("A", list.head.getNext().getData());
    }
}

